/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class MaximumAverageSubarrayI {
    public static double findMaxAverage(int[] nums, int k) {
        int n=nums.length;
        int maxSum=0;
        int i = 0;
        for (; i < k;i++) {
			maxSum+=nums[i];
		}
        int sum=maxSum;
        while (i<n) {
			sum+=nums[i];
			sum-=nums[i-k];
			if(sum>maxSum){
				maxSum=sum;
			}
			i++;
		}
        return (double)maxSum/k;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
